package com.hzeng.util;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.RowSorter;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

import org.dom4j.Document;
import org.dom4j.Element;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;

public class ProgramMonitorUI {
	private MyQueue<List<Program>> myQueue = null;
	
	private static ProgramMonitorUI mainUI = new ProgramMonitorUI();
	
	public static ProgramMonitorUI getInstance() {
		if (mainUI == null) {
			mainUI = new ProgramMonitorUI();
		}
		return mainUI;
	}
	private static long interval = 2000l;
	public static int imageWidth = 600;
	public static int imageHeight = 500;
	
	private static int width = 800;
	private static int height = 600;
	
	private static int mainPanelWidth = 600;
	private static int mainPanelHeight = 500;
	
	private static int tabPanelWidth = 580;
	private static int tabPanelHeight = 500;
	
	private static int navigatorHeight = 350;
	
	private static int listWidth = 200;
	private static int listHeight = 400;
	
	@SuppressWarnings("unused")
	private static int consolePanelWidth = 580;
	private static int consolePanelHeight = 100;
	
	private static int southPanelWidth = 595;
	private static int southPanelHeight = 100;	
	
	@SuppressWarnings("unchecked")
	public void initClient() {
		String confFilePath = "conf.xml";
		Document doc = XMLUtil.getXMLDoc(confFilePath);
		Element root = doc.getRootElement();
		Element ui= root.element(Constants.UI);
		List<Element> childNode = ui.elements();
		if (childNode.size() > 0) {
			for (int i = 0; i < childNode.size(); i++) {
				Element child = childNode.get(i);
				if (child.getName().equals(Constants.UI_WIDTH)) {
					width = new Integer(child.getText());
				}else if (child.getName().equals(Constants.UI_HEIGHT)) {
					height = new Integer(child.getText());
				}else if (child.getName().equals(Constants.UI_MAINPANEL_WIDTH)) {
					mainPanelWidth = new Integer(child.getText());
				}else if (child.getName().equals(Constants.UI_MAINPANEL_HEIGHT)) {
					mainPanelHeight = new Integer(child.getText());
				}else if (child.getName().equals(Constants.UI_TABPANEL_WIDTH)) {
					tabPanelWidth = new Integer(child.getText());
				}else if (child.getName().equals(Constants.UI_TABPANEL_HEIGHT)) {
					tabPanelHeight = new Integer(child.getText());
				}else if (child.getName().equals(Constants.UI_NAVIGATOR_HEIGHT)) {
					navigatorHeight = new Integer(child.getText());
				}else if (child.getName().equals(Constants.UI_LIST_WIDTH)) {
					listWidth = new Integer(child.getText());
				}else if (child.getName().equals(Constants.UI_LIST_HEIGHT)) {
					listHeight = new Integer(child.getText());
				}else if (child.getName().equals(Constants.UI_CONSOLEPANEL_WIDTH)) {
					consolePanelWidth = new Integer(child.getText());
				}else if (child.getName().equals(Constants.UI_CONSOLEPANEL_HEIGHT)) {
					consolePanelHeight = new Integer(child.getText());
				}else if (child.getName().equals(Constants.UI_SOUTHPANEL_WIDTH)) {
					southPanelWidth = new Integer(child.getText());
				}else if (child.getName().equals(Constants.UI_SOUTHEPANEL_HEIGHT)) {
					southPanelHeight = new Integer(child.getText());
				}
			}
		}
		Element server= root.element(Constants.SERVER);
		List<Element> serversNode = server.elements();
		if (serversNode.size() > 0) {
			for (int i = 0; i < serversNode.size(); i++) {
				Element child = serversNode.get(i);
				if (child.getName().equals(Constants.SERVER_INTERVAL)) {
					interval = new Long(child.getText());
				}else if (child.getName().equals(Constants.SERVER_IMAGE_WIDTH)) {
					imageWidth = new Integer(child.getText());
				}else if (child.getName().equals(Constants.SERVER_IMAGE_HEIGHT)) {
					imageHeight = new Integer(child.getText());
				}
			}
		}
		
	}
	
	private JFrame frame = null;
	private JPanel contentPane = null;
	
	private JPanel mainPanel = null;
	private JPanel listPanel = null;
	private JScrollPane navigatorPanel = null;
	private JScrollPane consolePanel = null;
	private JTabbedPane tabPane = null;
	
	private JPanel vmTab = null;
	private JPanel memoryTab = null;
	private JPanel cpuTab = null;
	
	private ChartPanel memoryChartPanel = null;
	private ChartPanel cpuChartPanel = null;
	private ChartPanel vmChartPanel = null;
	
	private JPanel memorySystemTab = null;
	private JPanel cpuSystemTab = null;
	private JPanel ioSystemTab = null;
	
	private ChartPanel memorySystemChartPanel = null;
	private ChartPanel cpuSystemChartPanel = null;
	private ChartPanel ioSystemChartPanel = null;
	
	JList convertList = null;
	private JTable destProgramTable = null;
	private JTextArea consoleArea = null;
	private static JFileChooser directoryChooser = null;
	private JButton recordButton = null;
	private JButton browserButton = null;
	private File saveDirectory = null;
	
	Map<Integer, JFreeChart> charts = null;
	

	public  MyQueue<List<Program>> getMyQueue() {
		return myQueue;
	}

	public void setMyQueue(MyQueue<List<Program>> myQueue) {
		ProgramMonitorUI.getInstance().myQueue = myQueue;
	}

	public File getSaveDirectory() {
		return saveDirectory;
	}

	public void setSaveDirectory(File saveDirectory) {
		this.saveDirectory = saveDirectory;
	}

	public JTable getDestProgramTable() {
		return destProgramTable;
	}

	public void setDestProgramTable(JTable destProgramTable) {
		this.destProgramTable = destProgramTable;
	}

	public JTextArea getConsoleArea() {
		return consoleArea;
	}

	public void setConsoleArea(JTextArea consoleArea) {
		this.consoleArea = consoleArea;
	}

	
	
	{
		// Set Look & Feel
		try {
			javax.swing.UIManager
					.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private ProgramMonitorUI(){
		frame = new JFrame("program monitor system");
		contentPane = new JPanel();
		
	}
	
	public void initFrame() {
		initClient();
		
		  frame.setContentPane(contentPane);
		  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
		  frame.setLocation(200, 200);
		  frame.setSize(width, height);
		  
		//  frame.setLayout(new BorderLayout());
		  contentPane.setLayout(new BorderLayout());
		  initQueue();
		  
		  initMenuPanel();
		  initListPanel();
		  initMainPanel();
		  
		  
		  frame.setVisible(true);
		  
		 
		//  frame.pack();  
	}
	
	public void initQueue() {
		myQueue = new MyQueue<List<Program>>();
		myQueue.setStarted(true);
		myQueue.setInterval(interval);
		
		Thread thread = new Thread(myQueue);
		thread.start();
	}
	
	
	public void initConsolePanel() {
		
		JPanel southPanel = new JPanel();
		southPanel.setLayout(null);
		southPanel.setPreferredSize(new Dimension(southPanelWidth, southPanelHeight));
		southPanel.setSize(new Dimension(southPanelWidth, southPanelHeight));
		
		JTabbedPane southTabPane = new JTabbedPane();
		southTabPane.setPreferredSize(new Dimension(southPanelWidth, consolePanelHeight));
		southTabPane.setSize(new Dimension(southPanelWidth, consolePanelHeight));
		southTabPane.setTabPlacement(JTabbedPane.TOP);
		southTabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
		
		
		ProgramTableModel systemTableModel = new ProgramTableModel();
		
		systemTableModel.setProgramList(new ArrayList<Program>());
		systemTableModel.setColumnCount(7);
		
		JTable systemProgramTable = new JTable(systemTableModel);
		RowSorter<javax.swing.table.TableModel> sorter = new TableRowSorter<TableModel>(systemProgramTable.getModel());
		systemProgramTable.setRowSorter(sorter);
		systemProgramTable.setVisible(true);
	//	systemProgramTable.setBackground(Color.WHITE);
		
		/*
		JScrollPane systemPanel = new JScrollPane(systemProgramTable);
		systemPanel.setPreferredSize(new Dimension(CONSOLEPANEL_WIDTH, CONSOLEPANEL_HEIGHT - 20));
		systemPanel.setSize(new Dimension(CONSOLEPANEL_WIDTH, CONSOLEPANEL_HEIGHT - 20));
		systemPanel.setAutoscrolls(true);
		
		JPanel tempPanel = new JPanel();
		tempPanel.add(systemPanel);
		
		
		Heartbeat heartbeat = new Heartbeat();
		heartbeat.setBeatFlag(true);
		heartbeat.setTable(systemProgramTable);
		Thread thread = new Thread(heartbeat);
		thread.start();
		
		southTabPane.addTab("tt2",tempPanel);
		southTabPane.setEnabledAt(0, false);
		southTabPane.setTitleAt(0, "System Information");
		*/
		
		consoleArea = new JTextArea(8, 40);  
		consolePanel = new JScrollPane(consoleArea);
		
		southTabPane.addTab("con",consolePanel);
		southTabPane.setEnabledAt(0, true);
		southTabPane.setTitleAt(0, "Console");
		
		southPanel.add(southTabPane);
		
		mainPanel.add(southPanel,"South");
	}
	
	
	public void initListPanel() {
	    
	    ProgramTableModel tableModel = new ProgramTableModel();
	    tableModel.setColumnCount(2);
	    
	    destProgramTable = new JTable(tableModel);
	    TableColumn firsetColumn = destProgramTable.getColumnModel().getColumn(0); 
	    firsetColumn.setPreferredWidth(150); 
	    firsetColumn.setMaxWidth(160); 
	    firsetColumn.setMinWidth(100); 
	    
	    TableColumn secondColumn = destProgramTable.getColumnModel().getColumn(1); 
	    secondColumn.setPreferredWidth(50);
	    secondColumn.setMaxWidth(100);
	    secondColumn.setMinWidth(40);
	    
	    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
	    renderer.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	    
	    TableColumn tc = destProgramTable.getColumn(Constants._NAME);
	    tc.setCellRenderer(renderer);
	    
	    RowSorter<javax.swing.table.TableModel> sorter = new TableRowSorter<TableModel>(destProgramTable.getModel());
	    destProgramTable.setRowSorter(sorter);
	    
	    destProgramTable.addMouseListener(new MouseListener() { 
			public void mousePressed(MouseEvent e) { 
			    
			} 

			public void mouseReleased(MouseEvent e) { 
			    
			} 

			public void mouseEntered(MouseEvent e) { 
			    
			} 

			public void mouseExited(MouseEvent e) { 
			    
			} 

			public void mouseClicked(MouseEvent e) { 
				if (e.getButton() == MouseEvent.BUTTON1) {
				     if (e.getClickCount() == 2) {
				    	 int convertRowIndex = destProgramTable.convertRowIndexToModel(destProgramTable.getSelectedRow());
				    	 Object pid = destProgramTable.getModel().getValueAt(convertRowIndex, 1);
				    	 
				    	 consoleArea.append("double click pid: " + pid.toString() + "\n");
				    	 
				    	 destroyChart();
				    	 createChart((Long)pid);
				     }
				}
			} 
		});
	    
	    listPanel = new JPanel();
	    listPanel.setLayout(new BorderLayout());
	    listPanel.setPreferredSize(new Dimension(listWidth, listHeight));
	    listPanel.setSize(new Dimension(listWidth, listHeight));
		listPanel.setVisible(true);
	    
	    navigatorPanel = new JScrollPane(destProgramTable);
	    navigatorPanel.setPreferredSize(new Dimension(listWidth, navigatorHeight));
	    navigatorPanel.setSize(new Dimension(listWidth, navigatorHeight));
	    navigatorPanel.setAutoscrolls(true);
	    
	    listPanel.add(navigatorPanel,"Center");
	    
	    JPanel localPanel = new JPanel();
	    localPanel.setPreferredSize(new Dimension(listWidth, listHeight - navigatorHeight));
	    localPanel.setSize(new Dimension(listWidth, listHeight - navigatorHeight));
	    localPanel.setLayout(new GridLayout(2,2));
	    
	    directoryChooser = new JFileChooser();
	    directoryChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
	    directoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	    
	    browserButton = new JButton("save as..");
	    browserButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {
            	//fileChooser.showDialog(frame,"File dialog");
            	int retval = directoryChooser.showSaveDialog(frame);
            	if(retval == JFileChooser.APPROVE_OPTION) {
            	
	            	saveDirectory = directoryChooser.getSelectedFile();
	            	if (saveDirectory != null) {
						if (saveDirectory.isDirectory()) {
						}
					}else {
						saveDirectory = new File(System.getProperty("user.dir"));
					}
	            	consoleArea.append("set data directory path:" + saveDirectory.getAbsolutePath() + "\n");
            	}
            //	consoleArea.append("stop \n");
            }
	    });
	    
	    recordButton = new JButton("Stopped");
	    recordButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {
            	if (event.getActionCommand().equals("Stopped")) {
            		ProgramTableModel tableModel = (ProgramTableModel)destProgramTable.getModel();
            		List<Program> programs = tableModel.getProgramList();
            		if (programs != null && programs.size() > 0) {
            			consoleArea.append("start record data \n");
                		recordButton.setText("Recording");
                		
                		browserButton.setEnabled(false);
                		
                		ProgramRecorder recorder = ProgramRecorder.getInstance();
                		
                		recorder.setSaveDirectory(saveDirectory);
                		recorder.setRecordFlag(true);
                		myQueue.addRecorderListener(recorder);
					}else {
						JOptionPane.showMessageDialog(null, "please select record programs in Setting->monitor setting");
					}
            		
				}else {
					ProgramRecorder recorder = ProgramRecorder.getInstance();
					recorder.setRecordFlag(false);
					
					myQueue.removeRecorderLister();
					
					consoleArea.append("stop record data \n");
					recordButton.setText("Stopped");
					myQueue.removeRecorderLister();
					
					browserButton.setEnabled(true);
				}
            	
            }
	    });
	    
	    JLabel filePathLabel=new JLabel("Save path:");
	    filePathLabel.setSize(new Dimension(50, 30));
	    
	    JLabel recordStatusLabel=new JLabel("Record status:");
	    recordStatusLabel.setSize(new Dimension(50, 30));
	    
	    localPanel.add(filePathLabel);
	    localPanel.add(browserButton);
	    localPanel.add(recordStatusLabel);
	    localPanel.add(recordButton);
	    
	    listPanel.add(localPanel,"South");
	    
	    contentPane.add(listPanel,"West");
		
	}
	
	public void initMenuPanel() {
		
		JMenuBar menuBar = new JMenuBar();
		JMenu fileMenu = new JMenu("File");
		fileMenu.setPreferredSize(new Dimension(60, 20));
		fileMenu.setSize(new Dimension(60, 20));
		
		JMenu settingMenu = new JMenu("Setting");
		settingMenu.setPreferredSize(new Dimension(60, 20));
		settingMenu.setSize(new Dimension(60, 20));
		
		JMenu convertionMenu = new JMenu("Convertion");
		convertionMenu.setPreferredSize(new Dimension(60, 20));
		convertionMenu.setSize(new Dimension(60, 20));
		
		JMenuItem timeSeriesMenuItem = new JMenuItem("To timeSeries Chart");
		timeSeriesMenuItem.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				new ConvertionDialog(frame);
				
			}
		});
		
		JMenuItem quitMenuItem = new JMenuItem("quit");
		quitMenuItem.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				int value=JOptionPane.showConfirmDialog(null, "Do you want to exit?");
			    if (value==JOptionPane.OK_OPTION) {
			    	//destory other resource
			    	myQueue.setStarted(false);
			    	
			    	System.exit(0);
			    }
				
			}
		});
		
		JMenuItem monitorMenuItem = new JMenuItem("monitor setting");
		monitorMenuItem.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				new ProgramDialog(frame);
				
			}
		});
		
		JMenuItem intervalSettingMenuItem = new JMenuItem("interval setting");
		intervalSettingMenuItem.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				String intervalString = JOptionPane.showInputDialog("please input time interval(millisecond):");
				if (intervalString != null) {
					long interval = 0l;
					try {
						interval = new Long(intervalString);
					} catch (Exception e2) {
						interval = 2000l;
					}
					myQueue.setInterval(interval);
					consoleArea.append("set time interval:" + interval + " millisecond \n");
				}else {
					
				}
			}
		});
		
		fileMenu.add(quitMenuItem);
		settingMenu.add(monitorMenuItem);
		settingMenu.add(intervalSettingMenuItem);
		convertionMenu.add(timeSeriesMenuItem);
		menuBar.add(fileMenu);
		menuBar.add(settingMenu);
		menuBar.add(convertionMenu);
		
		frame.setJMenuBar(menuBar);
	}
	
	public void destroyChart() {
		MyTimeSeriesChart.getInstance().setStartFlag(false);
		consoleArea.append("remove all tab...\n");
		memoryTab.removeAll();
		cpuTab.removeAll();
		vmTab.removeAll();
		
		memoryTab.updateUI();
		cpuTab.updateUI();
		vmTab.updateUI();
		
		cpuSystemTab.updateUI();
		memorySystemTab.updateUI();
		ioSystemTab.updateUI();
	}
	
	public void initChart() {
		MyTimeSeriesChart myChart = MyTimeSeriesChart.getInstance();
		createSystemChart(myChart);
		
		myChart.setStartFlag(false);
		
		//register chart in queue
		myQueue.addChartListener(myChart);
	}
	
	public void createSystemChart(MyTimeSeriesChart myChart) {
		
		myChart.setPid(0l);
		charts = myChart.createLiveCharts();
		
		consoleArea.append("create new system chart panel... \n");
		
		cpuSystemChartPanel = new ChartPanel(charts.get(Constants.CHART_SYS_CPU));
		cpuSystemChartPanel.setPreferredSize(new Dimension(tabPanelWidth - 20, tabPanelHeight - 100));
		cpuSystemChartPanel.setSize(new Dimension(tabPanelWidth, tabPanelHeight));
		cpuSystemTab.add(cpuSystemChartPanel);
		
		memorySystemChartPanel = new ChartPanel(charts.get(Constants.CHART_SYS_MEMORY));
		memorySystemChartPanel.setPreferredSize(new Dimension(tabPanelWidth - 20, tabPanelHeight - 100));
		memorySystemChartPanel.setSize(new Dimension(tabPanelWidth, tabPanelHeight));
		memorySystemTab.add(memorySystemChartPanel);
		
		ioSystemChartPanel = new ChartPanel(charts.get(Constants.CHART_SYS_IO));
		ioSystemChartPanel.setPreferredSize(new Dimension(tabPanelWidth - 20, tabPanelHeight - 100));
		ioSystemChartPanel.setSize(new Dimension(tabPanelWidth, tabPanelHeight));
		ioSystemTab.add(ioSystemChartPanel);
		
		myChart.setStartFlag(false);
		
		cpuSystemTab.updateUI();
		memorySystemTab.updateUI();
		ioSystemTab.updateUI();
	}
	
	public void createChart(long pid) {
		
		MyTimeSeriesChart myChart = MyTimeSeriesChart.getInstance();
		myChart.setPid(pid);
		
		charts = myChart.createLiveCharts();
		
		consoleArea.append("create new chart panel for program: " + pid + " \n");
		
		memoryChartPanel = new ChartPanel(charts.get(Constants.CHART_MEMORY));
		memoryChartPanel.setPreferredSize(new Dimension(tabPanelWidth - 20, tabPanelHeight - 100));
		memoryChartPanel.setSize(new Dimension(tabPanelWidth, tabPanelHeight));
		memoryTab.add(memoryChartPanel);
		
		cpuChartPanel = new ChartPanel(charts.get(Constants.CHART_CPU));
		cpuChartPanel.setPreferredSize(new Dimension(tabPanelWidth - 20, tabPanelHeight - 100));
		cpuChartPanel.setSize(new Dimension(tabPanelWidth, tabPanelHeight));
		cpuTab.add(cpuChartPanel);
		
		vmChartPanel = new ChartPanel(charts.get(Constants.CHART_VM));
		vmChartPanel.setPreferredSize(new Dimension(tabPanelWidth - 20, tabPanelHeight - 100));
		vmChartPanel.setSize(new Dimension(tabPanelWidth, tabPanelHeight));
		vmTab.add(vmChartPanel);
		
		myChart.setStartFlag(true);
		
		memoryTab.updateUI();
		cpuTab.updateUI();
		vmTab.updateUI();
	}
	
	public void initMainPanel() {
		mainPanel = new JPanel();
		mainPanel.setLayout(new BorderLayout());
		mainPanel.setPreferredSize(new Dimension(mainPanelWidth, mainPanelHeight));
		mainPanel.setSize(new Dimension(mainPanelWidth, mainPanelHeight));
		
		tabPane = new JTabbedPane();
		
		
		memoryTab = new JPanel();
		cpuTab = new JPanel();
		vmTab = new JPanel();
		
		memorySystemTab = new JPanel();
		cpuSystemTab = new JPanel();
		ioSystemTab = new JPanel();
		
		tabPane.addTab("tt2",cpuSystemTab);
		tabPane.setEnabledAt(0, true);
		tabPane.setTitleAt(0, Constants._SYS_CPU);
		
		tabPane.addTab("memory",memorySystemTab);
		tabPane.setEnabledAt(1, true);
		tabPane.setTitleAt(1, Constants._SYS_MEMORY);
		
		tabPane.addTab("tt2",ioSystemTab);
		tabPane.setEnabledAt(2, true);
		tabPane.setTitleAt(2, Constants._SYS_IO);
		
		
		tabPane.addTab("tt2",cpuTab);
		tabPane.setEnabledAt(3, true);
		tabPane.setTitleAt(3, Constants._CPU);
		
		tabPane.addTab("memory",memoryTab);
		tabPane.setEnabledAt(4, true);
		tabPane.setTitleAt(4, Constants._MEMORY);
		
		tabPane.addTab("tt2",vmTab);
		tabPane.setEnabledAt(5, true);
		tabPane.setTitleAt(5, Constants._VM);
		
		
		tabPane.setPreferredSize(new Dimension(tabPanelWidth, tabPanelHeight));
		tabPane.setSize(new Dimension(tabPanelWidth, tabPanelHeight));
		tabPane.setTabPlacement(JTabbedPane.TOP);
		tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
		
		mainPanel.add(tabPane,"Center");
		initConsolePanel();
		
		contentPane.add(mainPanel,"Center");
		
		initChart();
	}
	
	public void initComponents() {
		 initFrame(); 
	}
	
	public void run() {
		initComponents();
	}
	
	public static void main(String[] args) {  
		   
		ProgramMonitorUI ui = ProgramMonitorUI.getInstance();
		ui.run();
		   
	}  
}
